<template>
  <a-card :bordered="false">
    <div class="table-operator" style="display: flex; justify-content: space-between">
      <!-- <a-button v-if="hasPerm('Base_District.Add')" type="primary" icon="plus" @click="handleAdd()">新建</a-button>
            <a-button v-if="hasPerm('Base_District.Delete')" type="primary" icon="minus"
                @click="handleDelete(selectedRowKeys)" :disabled="!hasSelected()" :loading="loading">删除</a-button> -->
      <!-- <a-button type="primary" :disabled="selectedRowKeys.length<=0" icon="link" @click="handleEdit('all')">批量关联</a-button> -->
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="24" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <a-select-option key="code">编码</a-select-option>
                <a-select-option key="name">名称</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" @keydown.enter="getDataList" />
            </a-form-item>
            <a-form-item>
              <a-button
                type="primary"
                @click="
                  () => {
                    this.pagination.current = 1
                    this.getDataList()
                  }
                "
                >查询
              </a-button>
              <a-button
                style="margin-left: 8px"
                @click="
                  queryParam = { condition: 'code' }
                  getDataList()
                "
                >重置
              </a-button>
              <a-button v-if="hasPerm('AA_Inventory.Add')" type="primary" @click="handleAdd">新增 </a-button>
              <a-button style="" type="primary" @click="exportData('产品开票目录对照表')">导出 </a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <!-- <a-button type="primary" icon="download" @click="downloadTemplate">下载模板</a-button> -->
      <!-- <a-button type="primary" icon="upload" @click="handleImport()">导入</a-button> -->
    </div>
    <div class="table-page-search-wrapper"></div>

    <a-table
      ref="table"
      :scroll="{ y: 'calc(100vh - 330px)' }"
      :columns="columns"
      :rowKey="(row) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="true"
      size="small"
    >
      <span slot="TaxRate" slot-scope="text, scope">{{ text.substr(0, text.length - 1) }}</span>
      <span slot="CreateTime" slot-scope="CreateTime">{{ timeFormat(CreateTime, 'YYYY-MM-DD') }}</span>
      <span slot="IsTax" slot-scope="text, record">
        <template>
          <a-tag :color="record.IsTax ? 'blue' : 'orange'">{{ record.IsTax ? '是' : '否' }}</a-tag>
        </template>
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <!-- <a @click="handleAssociation(record.code)">关联税务目录</a> -->
          <a v-if="hasPerm('AA_Inventory.Edit')" @click="handleEdit(record)">编辑</a>
          <a-divider v-if="hasPerm('AA_Inventory.Edit')" type="vertical" />
          <a @click="handleAssociationOut(record)">关联税务目录</a>
          <a-divider v-if="hasPerm('AA_Inventory.Delete')" type="vertical" />
          <a v-if="hasPerm('AA_Inventory.Delete')" @click="handleDelete(record.Id)">删除</a>
          <!-- <a v-if="hasPerm('Base_District.Edit')" @click="handleEdit(record.Id)">设置单价</a> -->
        </template>
      </span>
    </a-table>
    <!-- 给导出用 -->
    <a-table
      v-show="isTableExport"
      ref="tableExport"
      :scroll="{ y: tableHeight }"
      :columns="columnsExport"
      :rowKey="(row) => row.Id"
      :dataSource="dataExport"
      :pagination="pagination"
      :loading="loading"
      :bordered="true"
      size="small"
    >
      <!-- 建档日期格式化 -->
      <span slot="madeDate" slot-scope="madeDate">{{ timeFormat(madeDate, 'YYYY-MM-DD') }}</span>
    </a-table>
    <a-drawer
      title="已关联税务目录"
      placement="right"
      :closable="false"
      width="50%"
      :visible="visible"
      @close="onClose"
    >
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="10">
            <a-button type="primary" style="margin-bottom: 20px; margin-right: 8px" @click="handleAddS('1')"
              >添加
            </a-button>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        :scroll="{ y: tableHeight }"
        :columns="beforeAssociationColumns"
        :dataSource="beforeAssociation"
        :rowKey="(row) => row.Id"
        :pagination="pagination1"
        :loading="loading1"
        @change="handleTableChange1"
        :bordered="true"
        size="small"
      >
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleDeleteAssociation(record.RelatId)">删除</a>
          </template>
        </span>
      </a-table>

      <div
        :style="{
          position: 'absolute',
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e8e8e8',
          padding: '10px 16px',
          textAlign: 'right',
          left: 0,
          background: '#fff',
          borderRadius: '0 0 4px 4px',
        }"
      >
        <a-button style="margin-right: 8px" @click="onClose"> 取消 </a-button>
        <a-button type="primary" @click="associationOK"> 确定 </a-button>
      </div>
    </a-drawer>
    <a-drawer
      title="关联税务目录"
      placement="right"
      :closable="false"
      width="50%"
      :visible="visiblees"
      @close="onClosees"
    >
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="10">
            <a-col :md="10" :sm="24">
              <a-form-item>
                <a-input
                  v-model="queryParam2.keyword"
                  placeholder="物料名称"
                  @keydown.enter="
                    () => {
                      this.pagination2.current = 1
                      this.handleAddS()
                    }
                  "
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-button
                type="primary"
                @click="
                  () => {
                    this.pagination2.current = 1
                    this.handleAddS()
                  }
                "
                >查询
              </a-button>
              <a-button
                style="margin-left: 8px"
                @click="
                  () => {
                    this.pagination2.current = 1
                    this.queryParam2 = {
                      condition: 'TM_Name',
                      keyword: '',
                    }
                    this.handleAddS()
                  }
                "
                >重置
              </a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        ref="table"
        :scroll="{ y: tableHeight }"
        :columns="associationColumns"
        :rowKey="(row) => row.Id"
        :dataSource="association"
        :pagination="pagination2"
        :loading="loading2"
        @change="handleTableChange2"
        :rowSelection="{ selectedRowKeys: selectedRowKeys1, onSelect: onSelect, type: 'radio' }"
        :bordered="true"
        size="small"
      >
      </a-table>
      <div
        :style="{
          position: 'absolute',
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e8e8e8',
          padding: '10px 16px',
          textAlign: 'right',
          left: 0,
          background: '#fff',
          borderRadius: '0 0 4px 4px',
        }"
      >
        <a-button style="margin-right: 8px" @click="onClosees"> 取消 </a-button>
        <a-button :disabled="submitDisabled" type="primary" @click="associationOK"> 确定 </a-button>
      </div>
    </a-drawer>
    <a-modal title="关联税务目录" :visible="visibleSetPrice" @ok="handleOk" @cancel="handleCancel">
      <div>
        <span>税务目录：</span
        ><a-select v-model="TaxValue" style="width: 350px">
          <a-select-option v-for="i in TaxList" :value="i.Id" :key="i.Id">
            {{ i.TM_Name }}
          </a-select-option> </a-select
        ><a-button style="margin-left: 4px" type="primary" :disabled="disabled" @click="handleOpenChoose">
          <a-icon type="search" />
        </a-button>
      </div>
      <div style="margin: 20px 0">
        <!-- v-model="IsTax" -->
        <span style="margin-left: 28px">单价：</span
        ><a-input @change="setMon" v-model="setPrice" style="width: 300px"></a-input
        ><a-checkbox style="margin-left: 20px" :checked="IsTax ? true : false" @change="onChange"> 含税 </a-checkbox>
      </div>
      <div>
        <span style="margin-left: 28px">税率：</span
        ><a-input-number v-model="TaxRate" style="width: 350px"></a-input-number
        ><span style="margin-left: 10px">%</span>
      </div>
    </a-modal>
    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import * as XLSX from 'xlsx'
import FileSaver from 'file-saver'
const columns = [
  { title: '货物编码', dataIndex: 'code' },
  { title: '货物名称', dataIndex: 'name' },
  { title: '规格', dataIndex: 'specification' },
  { title: '单价', dataIndex: 'TaxUnitPrice', align: 'right' },
  { title: '是否含税', dataIndex: 'IsTax', align: 'center', width: '80px', scopedSlots: { customRender: 'IsTax' } },
  { title: '税率', dataIndex: 'TaxRate', align: 'right', scopedSlots: { customRender: 'TaxRate' } },
  {
    title: '操作',
    key: 'action',
    width: '200px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]
const columnsExport = [
  { title: '货物编码', dataIndex: 'code' },
  { title: '货物名称', dataIndex: 'name' },
  { title: '规格', dataIndex: 'specification' },
  { title: '建档日期', dataIndex: 'madeDate', scopedSlots: { customRender: 'madeDate' } },
]
// 已关联税务目录
const beforeAssociationColumns = [
  { title: '税务编码', dataIndex: 'Taxproductcode' },
  { title: '物料名称', dataIndex: 'Taxproductname' },
  { title: '物料规格', dataIndex: 'TM_Specs' },
  { title: '物料单价', dataIndex: 'TM_UnitPrice', align: 'right' },
  { title: '税率', dataIndex: 'TM_TaxRate' },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
]
// 关联税务目录
const associationColumns = [
  { title: '税务编码', dataIndex: 'TM_TaxCode' },
  { title: '物料简码', dataIndex: 'TM_AbbCode' },
  { title: '物料名称', dataIndex: 'TM_Name' },
  { title: '物料规格', dataIndex: 'TM_Specs' },
  { title: '计量单位', dataIndex: 'TM_Unit' },
  { title: '物料单价', dataIndex: 'TM_UnitPrice', align: 'right' },
  { title: '是否含税', dataIndex: 'TM_IsTax' },
  { title: '税率', dataIndex: 'TM_TaxRate' },
]
export default {
  components: {
    EditForm,
  },
  mounted() {
    this.$nextTick(() => {
      // 页面渲染完成后的回调
      this.tableHeight = this.getTableHeight(true) + 24
    })
    this.getDataList()
  },
  data() {
    return {
      // 是否显示导出的表格
      isTableExport: false,
      leading: '',
      tableHeight: 570, // 表格高度
      data: [],
      dataExport: [], //给导出用
      pagination: {
        current: 1,
        pageSize: 20,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true,
      },
      // 第一层drawer
      pagination1: {
        current: 1,
        pageSize: 20,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true,
      },
      // 第二层drawer
      pagination2: {
        current: 1,
        pageSize: 20,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true,
      },
      filters: {},
      submitDisabled: true,
      filters1: {},
      filters2: {},
      sorter: { field: 'Id', order: 'desc' },
      loading: false,
      columns,
      columnsExport,
      queryParam: {
        condition: 'code',
      },
      visible: false, // 关联税务目录弹框
      beforeAssociationColumns, // 已关联表头
      associationColumns, // 已关联表头
      productsData: [], // 税务产品
      visiblees: false, // 第二层drawer
      beforeAssociation: [{ code: 1, name: 2, specification: 3 }], // 第一层数据，已关联
      association: [{ code: 11, name: 22, specification: 33 }], // 第二层数据，关联
      loading1: false, // 第一层drawer
      loading2: false, // 第一层drawer
      selectedRowKeys: [], // 最外层关联的选择框
      selectedRowKeys1: [], // 第二层关联选择框
      queryParam1: {
        condition: 'TM_Code',
      }, // 第一层查询框
      queryParam2: {
        condition: 'TM_Name',
        keyword: '',
      }, // 第二层查询框
      cInvCode: '', // 产品信息行列表code
      selectedRows: [],
      allData: [],
      TaxValue: '',
      visibleImport: false,
      visibleSetPrice: false,
      setPrice: '',
      setPriceId: '',
      TaxList: [],
      isAll: false,
      TaxRate: '',
      IsTax: 0,
      saveObj: {},
      disabled: false,
    }
  },
  methods: {
    downloadFileInfo(data, name) {
      const blob = new Blob([data])
      const link = document.createElement('a')
      link.href = URL.createObjectURL(blob)
      // console.log(link.href)
      link.download = name + '.xlsx'
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
      URL.revokeObjectURL(link.href)
    },
    // 导出
    exportData(excelName) {
      console.log('开始导出了')
      // 纯前端导出*************************
      // try {
      //   const $e = this.$refs['tableExport'].$el
      //   let $table = $e.querySelector('.el-table__fixed')
      //   if (!$table) {
      //     $table = $e
      //   }

      //   const wb = XLSX.utils.table_to_book($table, { raw: true })
      //   const wbout = XLSX.write(wb, {
      //     bookType: 'xlsx',
      //     bookSST: true,
      //     type: 'array',
      //   })
      //   FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), `${excelName}.xlsx`)
      // } catch (e) {
      //   if (typeof console !== 'undefined') console.error(e)
      // }
      // 待前后端接口联调**********************************8
      this.$http
        .post('/MaterialManagement/AA_Inventory/InventoryExport', {}, { responseType: 'blob' })
        .then((res) => {
          // window.open(res)
          this.downloadFileInfo(res, excelName)
        })
      // console.log(row.Id)
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.getDataList()
    },
    handleTableChange1(pagination, filters, sorter) {
      console.log(pagination)
      this.pagination1 = { ...pagination }
      this.filters1 = { ...filters }
      this.handleAssociation()
    },
    handleTableChange2(pagination, filters, sorter) {
      this.pagination2 = { ...pagination }
      this.filters2 = { ...filters }
      this.handleAddS()
      if (JSON.parse(localStorage.getItem('CHECK-BOX')) && JSON.parse(localStorage.getItem('CHECK-BOX')).length > 0) {
        this.selectedRowKeys1 = JSON.parse(localStorage.getItem('CHECK-BOX'))
      }
    },
    handleOpenChoose() {
      this.handleAddS('1')
    },
    //新增
    handleAdd() {
      this.$refs.editForm.openForm(null, '新增产品开票目录对照表')
    },
    handleEdit(record) {
      this.$refs.editForm.openForm(record.Id, '编辑产品开票目录对照表')
    },
    getDataList() {
      this.selectedRowKeys = []
      this.loading = true
      this.$http
        .post('/MaterialManagement/AA_Inventory/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters1,
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data
          // 过滤否含税的 给导出表格使用
          let dataExport = resJson.Data.filter((item) => !item.IsTax)
          this.dataExport = dataExport

          this.data.forEach((item) => {
            item.TaxRate = item.TaxRate ? (item.TaxRate += '%') : ''
            item.TaxUnitPrice = this.$options.filters.NumberFormatss(item.TaxUnitPrice)
          })
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    handleAssociationOut(record) {
      this.TaxValue = ''
      this.setPrice = ''
      this.IsTax = 0
      this.TaxRate = ''
      this.saveObj = {
        Id: record.TaxId,
        TM_Code: record.TmCode,
        TM_TaxCode: record.TaxCode,
      }
      if (record == 'all') {
        this.isAll = true
      } else {
        this.isAll = false
        this.IsTax = record.IsTax
        this.setPrice = record.TaxUnitPrice
        this.TaxValue = record.TaxName
        this.TaxRate = record.TaxRate.replace('%', '')
        this.setPriceId = record.code
      }
      this.visibleSetPrice = true
    },
    onChange(e) {
      console.log(e)
      this.IsTax = e.target.checked ? 1 : 0
    },
    // 导入文件类型
    handleChange(info) {
      if (info.file.status !== 'uploading') {
      }
      if (info.file.status === 'done') {
        if (info.file.response.Success === false) {
          this.$message.error(`${info.file.name}文件,${info.file.response.Msg},请检查文件内容！ `)
        } else {
          this.$message.success(`${info.file.name}  文件上传成功！`)
          this.getDataList()
        }
        this.visible = false
      } else if (info.file.status === 'error') {
        this.$message.error(`${info.file.name} 文件上传失败！`)
      }
    },
    setMon() {
      if (isNaN(this.setPrice * 1)) {
        this.setPrice = ''
        return
      }
      if (isNaN(this.setPrice * 1)) {
        this.setPrice = parseFloat(this.setPrice)
      }
      const reg = /^\d+(\.\d{0,8})?$/
      let flag2 = false
      if (!reg.test(this.setPrice)) {
        flag2 = true
      }
      if (flag2) {
        this.$message.warning('请输入正确的价格，最多八位小数')
      }
    },
    handleOk() {
      if (!this.TaxValue) {
        this.$message.error('请选择税务目录')
        return
      } else if (!this.setPrice) {
        this.$message.error('请选择输入单价')
        return
      } else if (!this.TaxRate) {
        this.$message.error('请选择输入税率')
        return
      }
      const reg = /^\d+(\.\d{0,8})?$/
      let flag2 = false
      if (!reg.test(this.setPrice)) {
        flag2 = true
      }
      if (flag2) {
        this.$message.warning('请输入正确的价格，最多八位小数')
        return
      }
      const arr = this.isAll ? this.selectedRowKeys : [this.setPriceId]
      this.$http
        .post('/MaterialManagement/AA_Inventory/ProductTaxCorrelation', {
          CInvCodes: arr,
          TaxId: this.saveObj.Id,
          TM_Code: this.saveObj.TM_Code || this.saveObj.TmCode,
          TM_TaxCode: this.saveObj.TM_TaxCode,
          TM_UnitPrice: Number(this.setPrice),
          IsTax: this.IsTax,
          TaxRate: Number(this.TaxRate),
        })
        .then((res) => {
          if (res.Success) {
            this.$message.success('关联成功!')
            this.getDataList()
            this.handleCancel()
          }
        })
        .catch((err) => {
          this.$message.error(err)
        })
    },
    // 删除已关联
    handleDeleteAssociation(id) {
      const thisObj = this
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        return new Promise((resolve, reject) => {
          thisObj.$http.post('/MaterialManagement/TaxMaterialsRelation/DeleteData', [id]).then((resJson) => {
            resolve()

            if (resJson.Success) {
              thisObj.$message.success('操作成功!')

              thisObj.handleAssociation()
            } else {
              thisObj.$message.error(resJson.Msg)
            }
          })
        })
      })
    },
    handleCancel() {
      this.visibleSetPrice = false
      this.selectedRowKeys1 = []
      this.TaxList = []
      this.setPrice = ''
    },
    // 关联选择
    onSelectChange1(selectedRowKeys, selectRows, id) {
      // console.log(selectedRowKeys, selectRows)
      this.selectedRowKeys1 = selectedRowKeys

      // 如果选择无数据，就创建一个新的加进去。
      if (!JSON.parse(localStorage.getItem('CHECK-BOX'))) {
        localStorage.setItem('CHECK-BOX', JSON.stringify(selectedRowKeys))
      } else {
        // 反则push
        const select = JSON.parse(localStorage.getItem('CHECK-BOX'))
        select.push(...selectedRowKeys)
        localStorage.removeItem('CHECK-BOX')
        localStorage.setItem('CHECK-BOX', JSON.stringify([...new Set(select)]))
      }
      this.selectedRowKeys1 = JSON.parse(localStorage.getItem('CHECK-BOX'))
    },
    // 点击关联税务目录
    handleAssociation(id) {
      // 查询按钮判断
      if (id) {
        this.cInvCode = id
      }
      this.visible = true
      this.loading1 = true
      this.$http
        .post('/InvoiceManagement/Inv_InvoiceApplyMain/GetRDRecordList', {
          PageIndex: this.pagination1.current,
          PageRows: this.pagination1.pageSize,
          SortField: 'TaxproductId',
          SortType: 'desc',
          Search: {
            Keyword: this.cInvCode,
          },
        })
        .then((resJson) => {
          this.loading1 = false
          this.beforeAssociation = resJson.Data
          const pagination = { ...this.pagination1 }
          pagination.total = resJson.Total
          this.pagination1 = pagination
        })
    },
    onSelect(record, selected, s) {
      this.selectedRowKeys1 = [record.Id]
      this.TaxList = s
      // let select = JSON.parse(localStorage.getItem('CHECK-BOX'));
      // if(selected){
      //     this.selectedRowKeys1.push(record.Id);
      // }else{
      //     //删除取消选择的
      //     select = select.filter(item => item != record.Id);
      //     this.selectedRowKeys1 = this.selectedRowKeys1.filter(item=>item != record.Id);
      // }
      // // 如果选择无数据，就创建一个新的加进去。
      // if (!JSON.parse(localStorage.getItem('CHECK-BOX'))) {
      //     localStorage.setItem('CHECK-BOX', JSON.stringify(this.selectedRowKeys1))
      // } else {
      //     //反则push
      //     select.push(...this.selectedRowKeys1);
      //     localStorage.removeItem('CHECK-BOX');
      //     localStorage.setItem('CHECK-BOX', JSON.stringify([...new Set(select)]))
      // }
      this.submitDisabled = this.selectedRowKeys1.length <= 0
    },
    onSelectAll(selected, selectedRows, changeRows) {
      const select = JSON.parse(localStorage.getItem('CHECK-BOX'))
      if (selected) {
        changeRows.forEach((item) => {
          this.selectedRowKeys1.push(item.Id)
        })
      } else {
        // //删除取消选择的
        // select = select.filter(item => item != record.Id);
        changeRows.forEach((item) => {
          select.forEach((item2, index) => {
            if (item2 == item.Id) {
              select.splice(index, 1)
            }
          })
        })
        this.selectedRowKeys1 = []
      }
      // 如果选择无数据，就创建一个新的加进去。
      if (!JSON.parse(localStorage.getItem('CHECK-BOX'))) {
        localStorage.setItem('CHECK-BOX', JSON.stringify(this.selectedRowKeys1))
      } else {
        // 反则push
        select.push(...this.selectedRowKeys1)
        localStorage.removeItem('CHECK-BOX')
        localStorage.setItem('CHECK-BOX', JSON.stringify([...new Set(select)]))
      }
      this.submitDisabled = this.selectedRowKeys1.length <= 0
    },
    // 关闭关联税务目录
    onClose() {
      this.visible = false
      this.pagination1.current = 1
    },
    // 深层关闭
    onClosees() {
      this.visiblees = false
      this.queryParam2 = { condition: 'TM_Name', keyword: '' }
      this.pagination2.current = 1
    },
    // 导入
    handleImport() {
      this.visibleImport = true
    },
    downloadTemplate() {},
    // 添加按钮
    handleAddS(add) {
      this.visiblees = true
      this.loading2 = true
      this.selectedRowKeys1 = []
      this.$http
        .post('MaterialManagement/TaxMaterials/GetDataList', {
          PageIndex: this.pagination2.current,
          PageRows: this.pagination2.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam2,
          ...this.filters2,
        })
        .then((resJson) => {
          this.loading2 = false
          if (add) {
            localStorage.removeItem('CHECK-BOX')
          }
          this.association = resJson.Data
          this.association.forEach((item) => {
            item.TM_TaxRate = item.TM_TaxRate + '%'
          })
          this.allData.push(...resJson.Data)
          this.allData = [...new Set(this.allData)]
          // 0否1是
          this.association.forEach((item) => {
            item.TM_IsTax = item.TM_IsTax ? '是' : '否'
          })
          if (this.association) {
            const pagination = { ...this.pagination2 }
            pagination.total = resJson.Total
            this.pagination2 = pagination
          }
        })
    },
    // 关联税务目录确定
    associationOK() {
      if (!this.selectedRowKeys1) {
        this.$message.error('请选择税务目录!')
        return
      }
      console.log(this.TaxList)
      this.TaxValue = this.TaxList[0].Id
      this.setPrice = this.TaxList[0].TM_UnitPrice
      this.IsTax = this.TaxList[0].TM_IsTax == '是' ? 1 : 0
      this.TaxRate = this.TaxList[0].TM_TaxRate.replace('%', '')
      this.visiblees = false
      this.saveObj = this.TaxList[0]
      // console.log(this.allData)
      // let arr = this.allData.filter(item => item.Id==this.selectedRowKeys1[0]);
      // arr.forEach(item => { item.cInvCode = this.cInvCode });
      // this.$http
      //     .post('/MaterialManagement/TaxMaterialsRelation/AddTaxMaterialsRelationList', arr)
      //     .then((resJson) => {
      //         if (resJson.Success) {
      //             this.$message.success('关联成功')
      //             this.visiblees = false;
      //             // localStorage.removeItem('CHECK-BOX');
      //             // this.handleAssociation()
      //         } else {
      //             this.$message.error('关联失败')
      //         }
      //     })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    handleDelete(ids) {
      var thisObj = this
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        return new Promise((resolve, reject) => {
          thisObj.$http.post('/MaterialManagement/AA_Inventory/DeleteData', [ids]).then((resJson) => {
            resolve()

            if (resJson.Success) {
              thisObj.$message.success('操作成功!')

              thisObj.getDataList()
            } else {
              thisObj.$message.error(resJson.Msg)
            }
          })
        })
      })
    },
  },
}
</script>

<style lang="less" scoped>
/deep/ .ant-card-body {
  padding-bottom: 0px;
}
</style>
